package com.jingan.nursinghome.regulatory.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import cn.android.support.v7.lib.sin.crown.base.BaseView;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/10/17.
 */

public class PageView extends BaseView {
    public PageView(Context context) {
        super(context);
    }

    public PageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = ProportionUtils.getInstance().adapterInt(103);
        setMeasuredDimension(width, width);
    }

    int selectColrBg = Color.parseColor("#4B97F0");//选择颜色
    //    int deaultColorBg = Color.parseColor("#D8E2EA");//默认背景颜色
    int deaultColorBg = Color.parseColor("#fc3778");//默认背景颜色
    int selectTextColor = Color.parseColor("#FFFFFF");//选中字体颜色
    int defaultTextColor = Color.parseColor("#FFFFFF");//默认字体颜色
    int TextSize = ProportionUtils.getInstance().adapterInt(26);
    boolean isSelect = false;//是否选中。
    public String start, end;//开始页，结束页

    boolean isScore = false;//是否已经打分

    public void setPage(String start, String end, boolean isSelect, boolean isScore) {
        this.start = start;
        this.end = end;
        this.isSelect = isSelect;
        this.isScore = isScore;
        invalidate();
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);

        if (start == null && end == null) {
            return;
        }

        textPaint.setTextAlign(Paint.Align.CENTER);
        textPaint.setTextSize(TextSize);
        if (isSelect) {
            paint.setColor(selectColrBg);
            canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, paint);
            textPaint.setColor(selectTextColor);
        } else {
            if (isScore) {
                paint.setColor(Color.parseColor("#00d8ff"));
            } else {
                paint.setColor(deaultColorBg);
            }
            canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, paint);
            textPaint.setColor(defaultTextColor);
        }
        int y = (getHeight() - TextSize) / 2 + TextSize;
        if (end.equals(start)) {
            canvas.drawText(start, getWidth() / 2, y, textPaint);
        } else {
            String info = start + "-" + end;
            canvas.drawText(info, getWidth() / 2, y, textPaint);
        }
    }
}
